/*
**  一个不属于其他模块的模块
*/
WHOOPSFEED.base = (function(){
	return {
		/*
		**	系统初始化
		*/
		init : function(){
            //检查播放器版本
            //WHOOPSFEED.base.check_browser_version();

			//加载新手帮助
            //WHOOPSFEED.base.help();

            WHOOPSFEED.base.slider_show();

            WHOOPSFEED.Mbaobei.init();
		},

        //切换显示用户框
        user_mess_box_hover: function(hclass, sclass) {

            var hover_div = $(hclass), show_div = $(sclass);

            show_div.hide();

            hover_div.parent().bind('mouseenter', function() {
                show_div.show();
            }).bind('mouseleave', function() {
                show_div.hide();
                show_div.bind('mouseenter',function(){
                    show_div.show();
                }).bind('mouseleave', function() {
                    show_div.hide();
                });
            });
        },

        //图片轮播
        slider_show : function (options) {
            var Settings = {
                slider_banner : "#index_slide_show ol",//banner 容器
                banner_tag : "li",//包裹banner内容的标签
                slider_text : "ul.switch_btn li.left",//text 容器
                text_tag : "span",//包裹banner内容的标签
                slider_hover : "ul.switch_btn li.right",//hover 容器
                hover_tag : "p",//包裹banner内容的标签
                trigger: 'mouseover', //触发事件 注意用mouseover代替hover
                speed: 300, //动画速度
                space: 5000 //时间间隔
            };

            Settings = $.extend({}, Settings, options);

            var index = 0;
            var $banner_box = $(document).find(Settings.slider_banner),$banner_contents = $banner_box.find(Settings.banner_tag);
            var $text_box   = $(document).find(Settings.slider_text),$text_contents = $text_box.find(Settings.text_tag);
            var $hover_box  = $(document).find(Settings.slider_hover),$hover_contents = $hover_box.find(Settings.hover_tag);

            function slider(){

                if (index >= $banner_contents.length){
                    index = 0;
                }
                $text_contents.eq(index).css("display",'block').siblings(Settings.text_tag).css("display",'none');
                $hover_contents.eq(index).addClass("on").siblings(Settings.hover_tag).removeClass("on");
                $banner_contents.eq(index).show().siblings().hide();
                $banner_contents.eq(index).animate({opacity:1},Settings.speed);
                $banner_contents.eq(index).siblings(Settings.banner_tag).animate({opacity:0},Settings.speed);

                index++;
            };

            var Timer = setInterval(slider, Settings.space);
            $hover_contents.bind(Settings.trigger,function(){
                _pause();
                index = $(this).index();
                slider();
                _continue();
            });
            $banner_box.hover(_pause,_continue);
            function _pause(){
                clearInterval(Timer);
            };
            function _continue(){
                Timer = setInterval(slider, Settings.space);
            };

        },

        //帮助层
		help : function(){

            if(!$.browser.msie || ($.browser.msie && $.browser.version < 9)){
                $('body').append(NoviceHelpTemp({'real_id': 1}));
                //IE6,7,8基本就告别新手帮助了
                $('#step1').show();
                $('.helpclose').on('click', function(){
                    $('#help').remove();
                });
                $('.next').on('click', function(){
                    var obj = $(this).parents('.step');
                    var step = obj.attr('step');
                    obj.hide();
                    $('#step' + (parseInt(step) + 1)).show();
                });
                $('.over').on('click', function(){
                    $('#help').remove();
                });
            }

		},

        check_browser_version : function(){
            //IE6升级提示]
            $('body').html('<div class="update_browser">'+
                '<div class="subtitle">您正在使用的IE浏览器版本过低，<br>我们建议您升级或者更换浏览器，以便体验顺畅、兼容、安全的互联网。</div>'+
                '<div class="title">选择一款<span>新</span>浏览器吧</div>'+
                '<div class="browser">'+
                    '<a href="http://windows.microsoft.com/zh-CN/internet-explorer/downloads/ie" class="ie" target="_blank" title="ie浏览器">ie浏览器</a>'+
                    '<a href="http://www.google.cn/chrome/intl/zh-CN/landing_chrome.html" class="chrome" target="_blank" title="谷歌浏览器">谷歌浏览器</a>'+
                    '<a href="http://www.firefox.com.cn" class="firefox" target="_blank" title="火狐浏览器">火狐浏览器</a>'+
                    '<a href="http://www.opera.com" class="opera" target="_blank" title="opera浏览器">opera浏览器</a>'+
                    '<a href="http://www.apple.com.cn/safari" class="safari" target="_blank" title="safari浏览器">safari浏览器</a>'+
                '</div>'+
                '<div class="bottomtitle">[&nbsp;<a href="http://www.theie6countdown.cn" target="_blank">对IE6说再见</a>&nbsp;]</div>'+
            '</div>');
        }
	}
})();

;(function($) {
	if (!$)
		return;
	$.fn.placehorder = function(texts, interval) {
		if (texts == null || texts.length == 0)
			return this;
		var ele = this.filter(':text');
		interval = interval || 5000;
		if (typeof texts == 'string') {
			texts = [ texts ];
		}
		ele.each(function(i, e) {
			var me = $(ele[i]), curIndex = 0, timer = null;
			var start = function(ele) {
				if (texts.length > 1) {
					if (timer != null)
						stop();
					timer = window.setInterval(function() {
						curIndex = ++curIndex % texts.length;
						$(ele).val(texts[curIndex]);
					}, interval);
				}
			};
			var stop = function() {
				console.log(timer);
				window.clearInterval(timer);
				timer = null;
			};
			me.bind('focus', function() {
				var me = $(this);
				if (me.val() == texts[curIndex]) {
					me.val('');
					stop();
				}
			});
			me.bind('blur', function() {
				var me = $(this);
				if (me.val() == '') {
					me.val(texts[curIndex]);
					start(me);
				}
			});
			me.val(texts[curIndex]);
			start(me);
		});
		return this;
	};
})(jQuery);